	
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'SelectCommandCurso' AND user_name(uid) = 'dbo')
	DROP PROCEDURE dbo.SelectCommandCurso
GO

CREATE PROCEDURE dbo.SelectCommandCurso
AS
	SET NOCOUNT ON;
SELECT     codigo, nombre, objetivo, silabo, creditos, horas_teoricas, horas_practicas, fk_prerrequisito, fk_equivalente, fk_facultad
FROM         Curso
GO


IF EXISTS (SELECT * FROM sysobjects WHERE name = 'SelectCommandCursoByFacultad' AND user_name(uid) = 'dbo')
	DROP PROCEDURE dbo.SelectCommandCurso
GO

select *from facultad
select *from usuario
CREATE PROCEDURE dbo.SelectCommandCursoByFacultad 2
(
	@fk_facultad int
)
AS
	SET NOCOUNT ON;
SELECT     
	codigo, nombre, 
	objetivo, silabo,
	creditos, horas_teoricas, 
	horas_practicas, fk_prerrequisito, 
	fk_equivalente, fk_facultad
FROM         Curso
WHERE fk_facultad = @fk_facultad  
GO


IF EXISTS (SELECT * FROM sysobjects WHERE name = 'InsertCommandCurso' AND user_name(uid) = 'dbo')
	DROP PROCEDURE dbo.InsertCommandCurso
GO

CREATE PROCEDURE dbo.InsertCommandCurso
(
	
	@nombre nchar(100),
	@objetivo nchar(100),
	@silabo nchar(100),
	@creditos int,
	@horas_teoricas int,
	@horas_practicas int,
	@fk_prerrequisito int,
	@fk_equivalente int,
	@fk_facultad int
)
AS

DECLARE @ID INT
SET @ID = (SELECT MAX(codigo) FROM [Curso])  
                                                                                                                                                                                                            
IF @ID IS NULL OR @ID=0                                                                                                                                                                                                                           
	SET @ID = 1                                                                                                                                                                                                                                      
ELSE                                                                                                                                                                                                                                                            
 SET @ID = @ID + 1  

	SET NOCOUNT OFF;
INSERT INTO [Curso] ([codigo], [nombre], [objetivo], [silabo], [creditos], [horas_teoricas], [horas_practicas], [fk_prerrequisito], [fk_equivalente], [fk_facultad])
 VALUES (@id, @nombre, @objetivo, @silabo, @creditos, @horas_teoricas, @horas_practicas, @fk_prerrequisito, @fk_equivalente, @fk_facultad);
	

GO

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'UpdateCommandCurso' AND user_name(uid) = 'dbo')
	DROP PROCEDURE dbo.UpdateCommandCurso
GO

CREATE PROCEDURE dbo.UpdateCommandCurso
(
	@Original_codigo int,
	@nombre nchar(100),
	@objetivo nchar(100),
	@silabo nchar(100),
	@creditos int,
	@horas_teoricas int,
	@horas_practicas int,
	@fk_prerrequisito int,
	@fk_equivalente int,
	@fk_facultad int
)
AS
	SET NOCOUNT OFF;
UPDATE [Curso] 
	SET [nombre] = @nombre, [objetivo] = @objetivo, [silabo] = @silabo,
	 [creditos] = @creditos, [horas_teoricas] = @horas_teoricas, [horas_practicas] = @horas_practicas, 
	 [fk_prerrequisito] = @fk_prerrequisito, [fk_equivalente] = @fk_equivalente, [fk_facultad] = @fk_facultad 
WHERE ([codigo] = @Original_codigo)
	
GO

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'DeleteCommandCurso' AND user_name(uid) = 'dbo')
	DROP PROCEDURE dbo.DeleteCommandCurso
GO

CREATE PROCEDURE dbo.DeleteCommandCurso
(
	@Original_codigo int
)
AS
	SET NOCOUNT OFF;
DELETE FROM [Curso] WHERE ([codigo] = @Original_codigo) 
GO

